package com.zhuge_new.Fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.zhuge_new.Adapter.DepositAdapter;
import com.zhuge_new.Base.BaseFragment;
import com.zhuge_new.R;
import com.zhuge_new.bean.DepositBean;
import com.zhuge_new.http.StringDialogCallback;
import com.zhuge_new.share.BaseHttp;
import com.zhuge_new.untils.DataParse;
import com.zhuge_new.untils.PreferencesUtils;

import net.idik.lib.slimadapter.SlimAdapter;
import net.idik.lib.slimadapter.SlimInjector;

import org.json.JSONException;
import org.json.JSONObject;

import javax.security.auth.login.LoginException;

/**
 * Created by lenovo on 2018-09-15.
 */

public class CardFragment2 extends BaseFragment {

    private View footerView;
    private RecyclerView re_list;
    protected boolean isInit = false;
    private int i=1;
    private ImageView iv_yhlogo;
    private TextView card_name;
    private TextView card_no;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.kabaofragment2, container, false);
        footerView = View.inflate(getContext(), R.layout.foor_card, null);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        isInit=true;
        init_title();
        getData();
    }

    public void init_title() {
        iv_yhlogo = getActivity().findViewById(R.id.iv_yhlogo);
        card_name = getActivity().findViewById(R.id.card_name);
        card_no = getActivity().findViewById(R.id.card_No);
    }



    public void getData() {
        OkGo.<String>post(BaseHttp.depositcard_data)
                .headers("token", PreferencesUtils.getString(getActivity(),"token"))
                .execute(new StringDialogCallback(getActivity()) {
                    @Override
                    public void onSuccessResponse(Response<String> response, String msg, String msgCode) {
                        try {
                            JSONObject obj=new JSONObject(response.body());
                            if (obj.getString("depositcards").equals("")){

                            }else {
                                DepositBean depositBean= (DepositBean) new DataParse().getBean(response.body(),DepositBean.class,0);
                                Glide.with(getActivity()).load(BaseHttp.baseImg1+depositBean.getDepositcards().get(0).getBankLogo()).into(iv_yhlogo);
                                card_name.setText(depositBean.getDepositcards().get(0).getBank());
                                card_no.setText("**** **** **** **** "+depositBean.getDepositcards().get(0).getDepositcardSuf());
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

}
